<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>医疗管家</title>
    <meta name="description" content="医疗管家">
    <meta name="keywords" content="医疗管家">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>用户管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>用户管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <el-row>
        <el-col :span="12">
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="权限名字/关键字" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                </div>
            </div>
            <div>
                <template>
                    <el-table
                            :data="tableData"
                            style="width: 100%">
                        <el-table-column label="序号" type="index" width="50"></el-table-column>
                        <el-table-column prop="name" align="center" label="权限名字"></el-table-column>
                        <el-table-column prop="keyword" align="center" label="关键字"></el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button
                                        size="mini"
                                        @click="handleEdit(scope.row)">编辑
                                </el-button>
                                <el-button
                                        size="mini"
                                        type="danger"
                                        @click="handleDelete(scope.row)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </template>
                <div class="pagination-container">
                    <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total"
                            :background="true">
                    </el-pagination>
                </div>
            </div>
        </el-col>

        <el-col :offset="2" :span="9">
            <el-card>
                <div slot="header">
                    <span v-if="true">修改权限</span>
                </div>
                <div class="text item">
                    <el-form ref="dataEditForm"  :model="formData" :rules="rules" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="权限名称:" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="关键字:">
                                    <el-input v-model="formData.keyword"/>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="说明:">
                                    <el-input v-model="formData.description" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>

                        <el-row>
                            <el-col :span="24" align="right">
                                <el-button @click="resetForm()">取消</el-button>
                                <el-button type="primary" @click="EditPermission()">确定</el-button>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </el-card>
        </el-col>
    </el-row>
<!--     添加-->
    <el-dialog
            title="添加权限"
            :visible.sync="dialogVisible"
            width="30%">
        <div class="text item">
            <el-form ref="dataEditForm"  :model="formData" :rules="rules" label-position="right" label-width="100px">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="权限名称:" prop="name">
                            <el-input v-model="formData.name"/>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="关键字:">
                            <el-input v-model="formData.keyword"/>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="24">
                        <el-form-item label="说明:">
                            <el-input v-model="formData.description" type="textarea"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="24" align="right">
                        <el-button @click="resetForm()">取消</el-button>
                        <el-button type="primary" @click="addition()">确定</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </el-dialog>
</div>

</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            formData: {},
            tableData: [],
            dialogVisible:false,
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            rules: {//校验规则
                name: [{required: true, message: '项目编码为必填项', trigger: 'blur'}],
                keyword: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
                description: [{required: true, message: '项目名称为必填项', trigger: 'blur'}],
            },
        },


        //钩子函数，VUE对象初始化完成后自动执行
        created() {
           this.listPage()
        },
        methods: {
            listPage(){
                axios.post("http://localhost:9002/permission/list",this.pagination).then(resp=>{
                    this.tableData = resp.data.rows;
                    this.pagination.total = resp.data.total;
                })
            },

            handleCurrentChange(currentPage){
               this.pagination.currentPage = currentPage;
               this.listPage();
            },
            addition(){
                axios.post("http://localhost:9002/permission/save",this.formData).then(resp=>{
                    if (resp.data.flag){
                        this.$message.success(resp.data.message);
                        this.dialogVisible= false;
                        this.listPage();
                        this.formData ={};
                    }else {
                        this.$message.error(resp.data.message);
                    }
                })

            },
            //添加
            handleCreate() {
               this.dialogVisible= true;
            },
            //查询
            findPage() {
               this.listPage();
            },
            //修改弹窗
            handleEdit(row) {
                console.log(row)
              axios.get(`http://localhost:9002/permission/${row.id}`).then(resp=>{
                  if (resp.data.flag){
                      this.$message.success(resp.data.message);
                      this.formData =resp.data.data
                  }else {
                      this.$message.error(resp.data.message);
                  }
              })
            },
            //修改
           EditPermission() {
               axios.put("http://localhost:9002/permission/update",this.formData).then(resp=>{
                   if (resp.data.flag){
                       this.$message.success(resp.data.message);
                       this.formData = {};
                       this.listPage();
                   }else{
                       this.$message.error(resp.data.message);
                   }
               })
            },
            //删除
            handleDelete(row) {
               axios.delete(`http://localhost:9002/permission/delete/${row.id}`).then(resp=>{
                   if (resp.data.flag){
                       this.$message.success(resp.data.message);
                       this.listPage();
                   }else {
                       this.$message.error(resp.data.message);
                   }
               })
            },
            resetForm() {

            },

        }
    })
</script>
</html>